package org.batch.config.batch.item.writer;

import org.batch.entity.Trading;
import org.batch.service.business.TradingService;
import org.springframework.batch.item.ItemWriter;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.Optional;

/**
 * 批处理数据库持久化CSV
 *
 * @author LiKun
 * @date 2021/9/27 18:55
 */
@Component
public class TradingCsvWriter implements ItemWriter<Trading> {
    @Resource
    private TradingService tradingService;

    @Override
    public void write(List<? extends Trading> tradings) throws Exception {
        Optional.ofNullable(tradings).ifPresent(vals -> vals.forEach(val -> tradingService.insertTrading(val)));
    }
}
